package com.edu.controller;

import com.codingapi.txlcn.tc.annotation.LcnTransaction;
import com.edu.bean.Dept;
import com.edu.feign.DeptFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/dept")
public class DeptController {

    @Autowired(required = false)
    private DeptFeignClient feignClient;

    @PostMapping("/addDept")
    @Transactional
    @LcnTransaction
    public String addDept(Dept dept){
        String result = feignClient.saveUser(dept);
        //故意写除0异常,模拟分布式事务的出现
        //int i = 1/0;
        return result;
    }
}
